# -*- coding: utf-8 -*-
"""
Created on Mon Sep 19 10:30:21 2016

@author: zhiqiang
"""

#第四题代码

#引入数据
#multi_phenos.txt
path = r"D:\2016试题\B\B题附件"
multi_pheno_file_name = 'multi_phenos.txt'
f = open(path+'\\'+multi_pheno_file_name)
strings = f.readlines()
multi_pheno_Data = []

for strs in strings:
    strs = strs.replace('\n','')
    strs = strs.split(' ')
    temp = []
    for s in strs:
        temp.append(int(s))
    multi_pheno_Data.append(temp)

def tranForDecisonData(index=10):    
    X = [[multi_pheno_Data[jj][ii] for ii in range(len(multi_pheno_Data[0])) if ii!=index-1] for jj in range(len(multi_pheno_Data))]
    y = [multi_pheno_Data[jj][ii] for jj in range(len(multi_pheno_Data)) for ii in range(len(multi_pheno_Data[0])) if ii==index-1]
    return X,y

from sklearn.cross_validation import cross_val_score
from sklearn.tree import DecisionTreeClassifier
clf = DecisionTreeClassifier()
clf.fit(X,y)
a = clf.predict(X)


forth_test = {}
for i in range(1,11):
    X,y = tranForDecisonData(i)
    clf = DecisionTreeClassifier()
    clf.fit(X,y)
    a = clf.predict(X)
    ans_temp = 0
    for index in range(len(a)):
        if a[index]==y[index]:
            ans_temp+=1
    forth_test.setdefault(i,ans_temp/1000)